package com.baizhi.service.impl;


import com.baizhi.dao.GuruMapper;
import com.baizhi.entity.Guru;
import com.baizhi.service.GuruService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: renpu
 * @Date: 2019/2/27 22:17
 * @Description:
 */

@Service
@Transactional
public class GuruServiceImpl implements GuruService {
    @Autowired
    private GuruMapper guruMapper;


    @Override
    public Map selectByPage(int rows, int page) {
        Map map=new HashMap();

        IPage<Guru> ipage=new Page<>(rows,page);

        IPage<Guru> guruIPage=guruMapper.selectPage(ipage,null);

        List<Guru> list=guruIPage.getRecords();

        long count=guruIPage.getTotal();

        map.put("rows",list);
        map.put("total",count);
        return map;
    }

    @Override
    public void insertGuru(Guru guru) {
        guruMapper.insert(guru);
    }

    @Override
    public void deleteGuru(int[] ids) {

        List<Integer> list=new ArrayList<>();
        for (int id:ids) {
            list.add(id);
        }

        guruMapper.deleteBatchIds(list);
    }

    @Override
    public List<Guru> selectAllGuru() {
        return guruMapper.selectList(null);
    }
}
